//
//  IdentityVerificationViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/17.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "IdentityVerificationViewController.h"
#import "Masonry.h"
#import "WKProgressHUD.h"
#import "GPosAPI.h"
#import "Tools.h"
#import "AFNetworking.h"
#import "SVProgressHUD.h"
#import "XMRegisterViewController.h"
//身份验证页面
@interface IdentityVerificationViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UILabel *shenFenYzLabel;
@property (nonatomic,strong) UIView *ViewOne;
@property (nonatomic,strong) UIView *ViewTwo;
@property (nonatomic,strong) UIView *ViewThree;
@property (nonatomic,strong) UIImageView *BottomView;
@property (nonatomic,strong) UIImageView *ImageOne;
@property (nonatomic,strong) UIImageView *ImageTwo;
@property (nonatomic,strong) UIImageView *ImageThree;
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UITextField *userNameText;
@property (nonatomic,strong) UITextField *SFZText;
@property (nonatomic,strong) UIView *ViewFour;
@property (nonatomic,strong) UIView *ViewFive;
@property (nonatomic,strong) WKProgressHUD *hud;
@property (nonatomic,assign) NSInteger num;//判断点击的那一个image
@property (nonatomic,strong) NSMutableArray *AllImageArr;
@property (nonatomic,strong) NSMutableArray *Arr1;
@property (nonatomic,strong) NSMutableArray *Arr2;
@property (nonatomic,strong) NSMutableArray *Arr3;
@property (nonatomic,strong) NSMutableArray *file;

@property (nonatomic,strong)NSString * shenFenyz;
@end

@implementation IdentityVerificationViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"身份验证";
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.Arr1=[NSMutableArray new];
    self.Arr2=[NSMutableArray new];
    self.Arr3=[NSMutableArray new];
    self.file=[NSMutableArray new];
    self.AllImageArr=[NSMutableArray new];
    self.view.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    self.automaticallyAdjustsScrollViewInsets =NO;
    //利用scrollView设置适配页面
    self.scrollView=[[UIScrollView alloc]init];
    
    [self.view addSubview:self.scrollView];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
        
    }];
    
    self.scrollView.alwaysBounceVertical=YES;
    
    self.scrollView.scrollEnabled=YES;
    
    self.scrollView.showsVerticalScrollIndicator=NO;
    [self loadData];
    
}

- (void)loadData{
    int userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    __weak typeof(self) weakSelf = self;
    NSDictionary * params = @{@"userId" : @(userId)};
    [GPosAPI requestIdentityResultWithParams:params andCallback:^(id obj) {
        NSLog(@"检测身份验证--%@",obj);
        if (obj==nil)
        {
            
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            weakSelf.shenFenyz = @"0";
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                
                NSDictionary * dict = [obj objectForKey:@"data"];
                if (dict.count == 0) {
                    NSLog(@"123");
                    weakSelf.shenFenyz = @"0";
                    
                }else{
                    NSLog(@"456");
                    weakSelf.shenFenyz = [dict objectForKey:@"reason"];
                }
              
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                //storyboard里的ID
                XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                vc.navigationController.navigationBarHidden=NO;
                //                    //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                self.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
            
            }
        }
        [self initUI];
    }];
    
}
-(void)initUI{
    NSLog(@"吐丝数据---%@",self.shenFenyz);
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    [self.scrollView addSubview:self.backgroundViews];
    [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        
//        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
//        make.left.equalTo(self.view.mas_left);
//        make.right.equalTo(self.view.mas_right);
//        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
        make.edges.equalTo(self.scrollView);
        
        make.width.equalTo(self.scrollView);
        
    }];
    
    if ([self.shenFenyz isEqualToString:@"0"])
    {
        self.shenFenYzLabel = [[UILabel alloc] init];
        self.shenFenYzLabel.backgroundColor = [UIColor whiteColor];
        self.shenFenYzLabel.font = [UIFont systemFontOfSize:15];
        self.shenFenYzLabel.text= @"";
        self.shenFenYzLabel.textColor = [UIColor redColor];
        [self.backgroundViews addSubview:self.shenFenYzLabel];
        [self.shenFenYzLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.backgroundViews.mas_top).offset(0);
            make.left.equalTo(self.backgroundViews.mas_left);
            make.right.equalTo(self.backgroundViews.mas_right);
            make.height.equalTo(@1);
        }];

    }
    else
    {
        self.shenFenYzLabel = [[UILabel alloc] init];
        self.shenFenYzLabel.backgroundColor = [UIColor whiteColor];
        self.shenFenYzLabel.font = [UIFont systemFontOfSize:15];
        self.shenFenYzLabel.text= [NSString stringWithFormat:@"  您上一次的身份认证失败，失败原因:%@",self.shenFenyz];
        self.shenFenYzLabel.numberOfLines = 2;
        self.shenFenYzLabel.textColor = [UIColor redColor];
        [self.backgroundViews addSubview:self.shenFenYzLabel];
        [self.shenFenYzLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.backgroundViews.mas_top).offset(0);
            make.left.equalTo(self.backgroundViews.mas_left);
            make.right.equalTo(self.backgroundViews.mas_right);
            make.height.equalTo(@60);
        }];
        
    }
    
    self.ViewOne=[[UIView alloc] init];
    self.ViewOne.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.ViewOne];
    [self.ViewOne mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.shenFenYzLabel.mas_bottom).offset(60);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(90));
    }];
    
    self.ViewTwo=[[UIView alloc] init];
    self.ViewTwo.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.ViewTwo];
    [self.ViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewOne.mas_bottom).offset(22);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(90));
    }];
    
    self.ViewThree=[[UIView alloc] init];
    self.ViewThree.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.ViewThree];
    [self.ViewThree mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewTwo.mas_bottom).offset(22);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(90));
    }];
    
    UILabel *topLab=[[UILabel alloc] init];
    topLab.textColor=[UIColor grayColor];
    topLab.text=@"请确保您使用本人的真实身份进行验证, 我们会保护您的个人信息安全";
    topLab.numberOfLines=2;
    topLab.font = [UIFont systemFontOfSize:15];
    [self.backgroundViews addSubview:topLab];
    [topLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.shenFenYzLabel.mas_bottom).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left).offset(15);
        make.right.equalTo(self.backgroundViews.mas_right).offset(-15);
        make.bottom.equalTo(self.ViewOne.mas_top).offset(-10);

    }];
    
    self.ViewFour=[[UIView alloc] init];
    self.ViewFour.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.ViewFour];
    [self.ViewFour mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewThree.mas_bottom).offset(22);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    self.ViewFive=[[UIView alloc] init];
    self.ViewFive.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.ViewFive];
    [self.ViewFive mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewFour.mas_bottom).offset(22);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(50));
        
    }];
    
    //退出登录按钮
    self.BottomView =[[UIImageView alloc] init];
    self.BottomView.image=[UIImage imageNamed:@"icon_anniu_f"];
    self.BottomView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tj:)];
    tap.delegate=self;
    [self.BottomView addGestureRecognizer:tap];
    [self.backgroundViews addSubview:self.BottomView];
    [self.BottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewFive.mas_bottom).offset(40);
        make.left.equalTo(self.backgroundViews.mas_left).offset(30);
        make.right.equalTo(self.backgroundViews.mas_right).offset(-30);
        
        
    }];
    //输入框
    self.userNameText=[[UITextField alloc] init];
    self.userNameText.placeholder=@"请输入您的真实姓名";
    [self.ViewFour addSubview:self.userNameText];
    [self.userNameText mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewFour.mas_top).offset(10);
        make.left.equalTo(self.ViewFour.mas_left).offset(20);
        make.right.equalTo(self.ViewFour.mas_right).offset(-20);
        make.bottom.equalTo(self.ViewFour.mas_bottom).offset(-10);
        
    }];
    
    self.SFZText=[[UITextField alloc] init];
    self.SFZText.placeholder=@"请输入您的身份证号";
    [self.ViewFive addSubview:self.SFZText];
    [self.SFZText mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewFive.mas_top).offset(10);
        make.left.equalTo(self.ViewFive.mas_left).offset(20);
        make.right.equalTo(self.ViewFive.mas_right).offset(-20);
        make.bottom.equalTo(self.ViewFive.mas_bottom).offset(-10);
        
    }];
    
    
    UILabel *backLab=[[UILabel alloc] init];
    backLab.text = @"提交验证";
    backLab.userInteractionEnabled =YES;
    backLab.textColor = [UIColor whiteColor];
    backLab.textAlignment = NSTextAlignmentCenter;
    [self.BottomView addSubview:backLab];
    [backLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.BottomView.mas_top).offset(25);
        make.left.equalTo(self.BottomView.mas_left);
        make.right.equalTo(self.BottomView.mas_right);
        make.height.equalTo(@(30));
    }];
    
    
    self.ImageOne = [[UIImageView alloc] init];
    self.ImageOne.image=[UIImage imageNamed:@"icon_tianjia"];
    self.ImageOne.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapOne=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SCZMPicture:)];
    tapOne.delegate =self;
    [self.ImageOne addGestureRecognizer:tapOne];
    [self.ViewOne addSubview:self.ImageOne];
    [self.ImageOne mas_makeConstraints:^(MASConstraintMaker *make) {
    
        make.left.equalTo(self.ViewOne.mas_left).offset(20);
        make.top.equalTo(self.ViewOne.mas_top).offset(6);
        
    }];
    
    self.ImageTwo = [[UIImageView alloc] init];
    self.ImageTwo.image=[UIImage imageNamed:@"icon_tianjia"];
    self.ImageTwo.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapTwo=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ZMPicture:)];
    tapTwo.delegate =self;
    [self.ImageTwo addGestureRecognizer:tapTwo];
    [self.ViewTwo addSubview:self.ImageTwo];
    [self.ImageTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.ViewTwo.mas_left).offset(20);
        make.top.equalTo(self.ViewTwo.mas_top).offset(6);
        
    }];
    
    self.ImageThree = [[UIImageView alloc] init];
    self.ImageThree.image=[UIImage imageNamed:@"icon_tianjia"];
    self.ImageThree.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapThree=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(FMPicture:)];
    tapThree.delegate =self;
    [self.ImageThree addGestureRecognizer:tapThree];
    [self.ViewThree addSubview:self.ImageThree];
    [self.ImageThree mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.ViewThree.mas_left).offset(20);
        make.top.equalTo(self.ViewThree.mas_top).offset(6);
        
    }];
    
    UILabel *labViewOne=[[UILabel alloc] init];
    labViewOne.text = @"手持本人身份证正面照和个人签字";
    [self.ViewOne addSubview:labViewOne];
    [labViewOne mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.ImageOne.mas_right).offset(10);
        make.top.equalTo(self.ViewOne.mas_top).offset(6);
        make.height.equalTo(@(18));
        make.right.equalTo(self.ViewOne.mas_right).offset(0);
    }];
    UILabel *labViewTwo=[[UILabel alloc] init];
    labViewTwo.text=@"请您上传一张手持身份证正面照和个人签字的照片,个人签字的内容包含'BC-e..com和当前日期。请确保照片和个人签字的内容清晰可见'";
    labViewTwo.textColor=[UIColor grayColor];
    labViewTwo.numberOfLines=4;
    [self.ViewOne addSubview:labViewTwo];
    [labViewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.ImageOne.mas_right).offset(10);
        make.top.equalTo(labViewOne.mas_bottom).offset(0);
        make.bottom.equalTo(self.ViewOne.mas_bottom).offset(0);
        make.right.equalTo(self.ViewOne.mas_right).offset(0);
    }];
    
    UILabel *labViewThree = [[UILabel alloc] init];
    labViewThree.text=@"本人身份证正面照片";
    [self.ViewTwo addSubview:labViewThree];
    [labViewThree mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.ViewTwo.mas_top).offset(24);
        make.left.equalTo(self.ImageTwo.mas_right).offset(10);
        make.right.equalTo(self.ViewTwo.mas_right).offset(0);
        make.height.equalTo(@(18));
        
    }];
    
    UILabel *labViewFour = [[UILabel alloc] init];
    labViewFour.text=@"请确保照片的内容完整清晰可见，身份证必须在有效期内。";
    labViewFour.numberOfLines=2;
    labViewFour.textColor=[UIColor grayColor];
    [self.ViewTwo addSubview:labViewFour];
    [labViewFour mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(labViewThree.mas_bottom).offset(0);
        make.left.equalTo(self.ImageTwo.mas_right).offset(10);
        make.right.equalTo(self.ViewTwo.mas_right).offset(-30);
        make.bottom.equalTo(self.ViewTwo.mas_bottom).offset(-12);
        
    }];
    
    UILabel *labViewFive = [[UILabel alloc] init];
    labViewFive.text=@"本人身份证背面照片";
    [self.ViewThree addSubview:labViewFive];
    [labViewFive mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.ViewThree.mas_top).offset(24);
        make.left.equalTo(self.ImageThree.mas_right).offset(10);
        make.right.equalTo(self.ViewThree.mas_right).offset(0);
        make.height.equalTo(@(18));
        
    }];
    
    UILabel *labViewSix = [[UILabel alloc] init];
    labViewSix.text=@"请确保照片的内容完整清晰可见，身份证必须在有效期内。";
    labViewSix.numberOfLines=2;
    labViewSix.textColor=[UIColor grayColor];
    [self.ViewThree addSubview:labViewSix];
    [labViewSix mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(labViewFive).offset(24);
        make.left.equalTo(self.ImageThree.mas_right).offset(10);
        make.right.equalTo(self.ViewThree.mas_right).offset(-30);
        make.bottom.equalTo(self.ViewThree.mas_bottom).offset(-12);
        
    }];
    
    
    
    
    if (IS_IPHONE5 || IS_IPHONE6)
    {
        labViewOne.font=[UIFont systemFontOfSize:12];
        labViewThree.font=[UIFont systemFontOfSize:12];
        labViewFive.font=[UIFont systemFontOfSize:12];
        labViewTwo.font=[UIFont systemFontOfSize:10];
        labViewFour.font=[UIFont systemFontOfSize:10];
        labViewSix.font=[UIFont systemFontOfSize:10];
    }else{
        
        labViewOne.font=[UIFont systemFontOfSize:14];
        labViewThree.font=[UIFont systemFontOfSize:14];
        labViewFive.font=[UIFont systemFontOfSize:14];
        labViewTwo.font=[UIFont systemFontOfSize:12];
        labViewFour.font=[UIFont systemFontOfSize:12];
        labViewSix.font=[UIFont systemFontOfSize:12];
    }
    
    if (self.backgroundViews.subviews.count>0){
        
        [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.backgroundViews.subviews.lastObject).offset(10);
            
        }];
        
    }
    
}
-(void)tj:(UIGestureRecognizer *)tp{
    
    NSLog(@"提交验证");
    if (self.Arr1.count==0)
    {
        self.hud=[WKProgressHUD popMessage:@"请添加本人手持身份证正面照" inView:self.view duration:1 animated:YES];
    }else if (self.Arr2.count==0){
        
         self.hud=[WKProgressHUD popMessage:@"请添加身份证正面照" inView:self.view duration:1 animated:YES];
    }else if (self.Arr3.count==0){
        
         self.hud=[WKProgressHUD popMessage:@"请添加身份证反面照" inView:self.view duration:1 animated:YES];
        
    }else if (self.userNameText.text.length==0){
         self.hud=[WKProgressHUD popMessage:@"请输入真实姓名" inView:self.view duration:1 animated:YES];
        
    }else if (self.SFZText.text.length==0){
        
         self.hud=[WKProgressHUD popMessage:@"请输入身份证号" inView:self.view duration:1 animated:YES];
    }else{//网络请求
        
        self.BottomView.userInteractionEnabled = NO;

        [self uploadPictures];
    }
    
}
-(void)uploadPictures{
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    
    
    manager.requestSerializer = [AFJSONRequestSerializer serializer];//请求
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];//响应
    
    
    [manager.requestSerializer setValue:@"iphone"forHTTPHeaderField:@"user-agent"];
    [manager.requestSerializer setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"user_token"]forHTTPHeaderField:@"user-token"];
    [manager.requestSerializer setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]forHTTPHeaderField:@"userId"];
    
    manager.requestSerializer.timeoutInterval = 50;
    
    //压缩图片
    
    for (UIImage *img in self.AllImageArr)
    {
        //压缩图片
        NSData *Data =UIImageJPEGRepresentation(img,0.5);
        
        [self.file addObject:Data];
        
    }
    /*
     参数：userId
     参数：realName
     参数：cardNumber
     参数：file
    
     */
    __weak typeof(self) weakSelf = self;
    int userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@(userId),@"userId",self.userNameText.text,@"realName",self.SFZText.text,@"cardNumber", nil];
    
// zhengshifu   http://148.163.164.19:8085/member/bindIdentity
//     ceshifu http://192.168.0.111:8085/member/bindIdentity
    //47.105.117.153:8000
//    NSString* IPStr = @"http://47.105.117.153:8085/member/bindIdentity";
    NSString* IPStr = @"http://148.163.164.19:8085/member/bindIdentity";
        [manager POST:IPStr parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
        //上传的参数(上传图片，以文件流的格式)
        for ( NSData *imageDatas  in self.file)
        {
        [formData appendPartWithFileData:imageDatas
                                    name:@"file"
                                fileName:fileName
                                mimeType:@"image/jpeg"];
        
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSDictionary *dataDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dataDic);
        if (dataDic==nil) {
            self.BottomView.userInteractionEnabled = YES;

            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
        }else{
            
            if ([[dataDic objectForKey:@"code"] integerValue]==200)
            {
                weakSelf.BottomView.userInteractionEnabled = YES;

                weakSelf.hud=[WKProgressHUD popMessage:@"上传成功" inView:weakSelf.view duration:1 animated:YES];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }else if ([[dataDic objectForKey:@"code"] integerValue]==401 || [[dataDic objectForKey:@"code"] intValue] == 402){
                weakSelf.BottomView.userInteractionEnabled = YES;

                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[dataDic objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }else{
                weakSelf.BottomView.userInteractionEnabled = YES;

                [SVProgressHUD showErrorWithStatus:[dataDic objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            }
        }
        
      
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        weakSelf.BottomView.userInteractionEnabled = YES;

        weakSelf.hud=[WKProgressHUD popMessage:@"上传失败" inView:self.view duration:1 animated:YES];
    }];
    
}
//手持本人身份证的点击事件
-(void)SCZMPicture:(UIGestureRecognizer *)tp{
    
    NSLog(@"1");
    //显示弹出框列表选择
    self.num=1;
    UIAlertController* alert = [[UIAlertController alloc] init];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
        //响应事件
        NSLog(@"action = %@", action);
    }];
    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        [self pickImage];
    }];
    UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        NSString* deviceModel = [Tools getCurrentDeviceModel];
        if([deviceModel isEqualToString:@"iPhone Simulator (i386)"] || [deviceModel isEqualToString:@"iPhone Simulator (x86_64)"])
        {
            
            UIAlertController* alerts = [UIAlertController alertControllerWithTitle:@"提示" message:@"拍照请用真机测试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultActions = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                //响应事件
                
            }];
            
            [alerts addAction:defaultActions];
            [self presentViewController:alerts animated:YES completion:nil];
            
        } else {
            [self snapImage];
        }
    }];
    [alert addAction:saveAction];
    [alert addAction:cancelAction];
    [alert addAction:deleteAction];
    [self presentViewController:alert animated:YES completion:nil];
    
}
//从相册里找
- (void) pickImage {
    
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    ipc.delegate = self;
    ipc.allowsEditing = YES;
    
    [self presentViewController:ipc animated:YES completion:nil];
    
}
//拍照
- (void)snapImage {
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
    ipc.delegate = self;
    ipc.allowsEditing = NO;
    [self presentViewController:ipc animated:YES completion:nil];
}
#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *infoKey = @"UIImagePickerControllerEditedImage";
    if(picker.sourceType==UIImagePickerControllerSourceTypeCamera){
        infoKey = @"UIImagePickerControllerOriginalImage";
    }
    
    UIImage *img = [info objectForKey:infoKey];
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
        UIImage *smallImage = [self scaleFromImage:img toSize:CGSizeMake(63.0f, 79.0f)];//将图片尺寸改为63*63
        if (self.num==1)
        {
            self.ImageOne.image=smallImage;
            [self.Arr1 addObject:smallImage];
            [self.AllImageArr addObject:smallImage];
        }else if (self.num==2){
            
            self.ImageTwo.image=smallImage;
            [self.Arr2 addObject:smallImage];
            [self.AllImageArr addObject:smallImage];
        }else{
            
            self.ImageThree.image=smallImage;
            [self.Arr3 addObject:smallImage];
            [self.AllImageArr addObject:smallImage];
        }
        //准备上传图片
//        [self uploadImage:smallImage];
    }];
}
// 改变图像的尺寸，方便上传服务器
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size {
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
//本人身份证正面照的点击事件
-(void)ZMPicture:(UIGestureRecognizer *)tp{
    
     NSLog(@"2");
    self.num=2;
    UIAlertController* alert = [[UIAlertController alloc] init];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
        //响应事件
        NSLog(@"action = %@", action);
    }];
    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        [self pickImage];
    }];
    UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        NSString* deviceModel = [Tools getCurrentDeviceModel];
        if([deviceModel isEqualToString:@"iPhone Simulator (i386)"] || [deviceModel isEqualToString:@"iPhone Simulator (x86_64)"])
        {
            
            UIAlertController* alerts = [UIAlertController alertControllerWithTitle:@"提示" message:@"拍照请用真机测试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultActions = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                //响应事件
                
            }];
            
            [alerts addAction:defaultActions];
            [self presentViewController:alerts animated:YES completion:nil];
            
        } else {
            [self snapImage];
        }
    }];
    [alert addAction:saveAction];
    [alert addAction:cancelAction];
    [alert addAction:deleteAction];
    [self presentViewController:alert animated:YES completion:nil];
    
}
//本人身份证反面照的点击事件
-(void)FMPicture:(UIGestureRecognizer *)tp{
    
     NSLog(@"3");
    self.num=3;
    UIAlertController* alert = [[UIAlertController alloc] init];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
        //响应事件
        NSLog(@"action = %@", action);
    }];
    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        [self pickImage];
    }];
    UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        //响应事件
        NSString* deviceModel = [Tools getCurrentDeviceModel];
        if([deviceModel isEqualToString:@"iPhone Simulator (i386)"] || [deviceModel isEqualToString:@"iPhone Simulator (x86_64)"])
        {
            
            UIAlertController* alerts = [UIAlertController alertControllerWithTitle:@"提示" message:@"拍照请用真机测试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultActions = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                //响应事件
                
            }];
            
            [alerts addAction:defaultActions];
            [self presentViewController:alerts animated:YES completion:nil];
            
        } else {
            [self snapImage];
        }
    }];
    [alert addAction:saveAction];
    [alert addAction:cancelAction];
    [alert addAction:deleteAction];
    [self presentViewController:alert animated:YES completion:nil];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
